import { cardData, monsterData, Monster, Magic, Tragic, Effect } from './card';
import { User, Duel } from './duel';


export class NormalMonster extends Monster {
    constructor(monsterData: monsterData, owner: User) {
        super(monsterData, owner);
    }
    effect() {
        return false;
    }
}


export class CeremonyMonster extends Monster {
    constructor(monsterData: monsterData, owner: User, effects: Effect[], lifeCycle: object) {
        super(monsterData, owner, effects, lifeCycle);
    }
    ceremonySummon(ceremonyMagic: CeremonyMagic, sacrifice: Monster[]) {
        this.specialSummon();
    }
}


export interface FusionMonster {
    require: Function
}

export class FusionMonster extends Monster {
    constructor(monsterData: monsterData, owner: User, effects: Effect[], lifeCycle: object, require: Function) {
        super(monsterData, owner, effects, lifeCycle);

        this.require = require;
    }
    fusionSummon(sacrifice: Monster[]) {
        if (this.require(sacrifice)) {
            this.specialSummon();
        }
    }
}


export interface SynchroMonster {
    require: Function
}

export class SynchroMonster extends Monster {
    constructor(monsterData: monsterData, owner: User, effects: Effect[], lifeCycle: object, require: Function) {
        super(monsterData, owner, effects, lifeCycle);

        this.require = require;
    }
    synchroSummon(tuner: Monster[], unTuner: Monster[]) {
        if (this.require(tuner, unTuner)) {
            this.specialSummon();
        }
    }
}


export interface XYZMonster {
    XYZtokens: Monster[]
}

export class XYZMonster extends Monster {
    constructor(monsterData: monsterData, owner: User, effects: Effect[], lifeCycle: object) {
        super(monsterData, owner, effects, lifeCycle);
    }
    XYZSummon(sacrifice: Monster[]) {
        let tmp = sacrifice.filter(monster => monster.currentData.level !== this.currentData.level);
        if (tmp.length === 0) {
            this.specialSummon();
            this.XYZtokens = sacrifice;
        }
    }
}


export class CeremonyMagic extends Magic {
    constructor(magicData: cardData, owner: User, effects: Effect[], lifeCycle: object) {
        super(magicData, owner, effects, lifeCycle);
    }
    ceremonySummon(ceremonyMonster: CeremonyMonster, sacrifice: Monster[]) {
        let stars = sacrifice.reduce((stars, monster) => {
            return stars + monster.currentData.level;
        }, 0);

        if (stars === this.currentData.level) {
            ceremonyMonster.ceremonySummon(this, sacrifice);
        }
    }
}